package cn.kgc.hotel.controller;


import cn.kgc.hotel.entity.Param.RoomParam;
import cn.kgc.hotel.entity.ReturnResultMessage;
import cn.kgc.hotel.entity.Room;
import cn.kgc.hotel.service.RoomService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class RoomsController {

    @Resource
    private RoomService roomService;

    @RequestMapping("/roomShow")
    public ReturnResultMessage getRoomList(Integer roomNums, String roomType, String roomFloor, String roomState){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        /*PageInfo pageInfo = roomService.showRoom();*/
        List<Room> roomList = roomService.showRoom(roomNums,roomType,roomFloor,roomState);

        returnResultMessage.setCode("success");
        returnResultMessage.setMsg("成功");
        returnResultMessage.setData(roomList);

        return returnResultMessage;
    }

    @RequestMapping("/addRoom")
    public ReturnResultMessage addRoomList(@RequestBody RoomParam roomParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = roomService.addRoom(roomParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("添加库存成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("添加库存失败");
        }
        return returnResultMessage;
    }

    @RequestMapping("/updateRoom")
    public ReturnResultMessage updateRoomList(@RequestBody RoomParam roomParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = roomService.updateRoom(roomParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("修改库存成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("修改库存失败");
        }
        return returnResultMessage;
    }

    @RequestMapping("/deleteRoom")
    public ReturnResultMessage deleteRoomList(@RequestBody RoomParam roomParam){
        ReturnResultMessage returnResultMessage = new ReturnResultMessage();
        boolean flag = roomService.deleteRoom(roomParam);
        if (flag) {
            returnResultMessage.setCode("success");
            returnResultMessage.setMsg("删除库存成功");
        } else {
            returnResultMessage.setCode("error");
            returnResultMessage.setMsg("删除库存失败");
        }
        return returnResultMessage;
    }
}
